package cn.terminus.biz.customer.contractselldefyoverdueapplicationinfo;

import cn.terminus.biz.customer.common.AbstractTerminusManager;
import cn.terminus.common.customer.bean.contractselldefyoverdueapplicationinfo.dto.*;
import cn.terminus.data.customer.contractselldefyoverdueapplicationinfo.dao.ContractSellDefyOverdueApplicationInfoDao;
import cn.terminus.result.common.exception.DataAccessException;
import cn.terminus.result.common.page.TerminusPageAble;
import cn.terminus.result.common.page.TerminusPageInfo;
import cn.terminus.result.common.util.BeanCopyUtils;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 合同出售办证违约(ContractSellDefyOverdueApplicationInfo)表服务实现类
 *
 * @author makejava
 * @since 2021-07-21 11:18:33
 */
@Component
public class ContractSellDefyOverdueApplicationInfoManager extends AbstractTerminusManager {
    @Autowired
    private ContractSellDefyOverdueApplicationInfoDao contractSellDefyOverdueApplicationInfoDao;

    public Integer add(ContractSellDefyOverdueApplicationInfoNewDto dto) throws DataAccessException {
        try {
            return contractSellDefyOverdueApplicationInfoDao.add(dto);
        } catch (Exception e) {
            logger.error("ContractSellDefyOverdueApplicationInfoManager新增失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer update(ContractSellDefyOverdueApplicationInfoEditDto dto) throws DataAccessException {
        try {
            return contractSellDefyOverdueApplicationInfoDao.update(dto);
        } catch (Exception e) {
            logger.error("ContractSellDefyOverdueApplicationInfoManager更新失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public List<ContractSellDefyOverdueApplicationInfoResultDto> gets(ContractSellDefyOverdueApplicationInfoGetsDto dto) throws DataAccessException {
        try {
            return contractSellDefyOverdueApplicationInfoDao.gets(dto);
        } catch (Exception e) {
            logger.error("ContractSellDefyOverdueApplicationInfoManager查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public List<ContractSellDefyOverdueApplicationInfoResultDto> query(ContractSellDefyOverdueApplicationInfoQueryDto dto) throws DataAccessException {
        try {
            return contractSellDefyOverdueApplicationInfoDao.query(dto);
        } catch (Exception e) {
            logger.error("ContractSellDefyOverdueApplicationInfoManager查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer delete(ContractSellDefyOverdueApplicationInfoDeleteDto dto) throws DataAccessException {
        try {
            return contractSellDefyOverdueApplicationInfoDao.delete(dto);
        } catch (Exception e) {
            logger.error("ContractSellDefyOverdueApplicationInfoManager删除失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public TerminusPageAble<ContractSellDefyOverdueApplicationInfoResultDto> page(ContractSellDefyOverdueApplicationInfoQueryDto dto, TerminusPageInfo page) throws DataAccessException {
        try {
            PageHelper.startPage(page.getCurrentPage(), page.getPageSize());
            Page<ContractSellDefyOverdueApplicationInfoResultDto> result = (Page<ContractSellDefyOverdueApplicationInfoResultDto>) contractSellDefyOverdueApplicationInfoDao.query(dto);
            return new TerminusPageAble<>(BeanCopyUtils.copy(result.getResult(), ContractSellDefyOverdueApplicationInfoResultDto.class), page, result.getTotal());
        } catch (Exception e) {
            logger.error("ContractSellDefyOverdueApplicationInfoManager分页查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer deleteWithContractId(Long id) throws DataAccessException {
        try {
            return contractSellDefyOverdueApplicationInfoDao.deleteWithContractId(id);
        } catch (Exception e) {
            logger.error("ContractSellDefyOverdueApplicationInfoManager删除失败，原因：", e);
            throw new DataAccessException(e);
        }
    }
}
